<template lang="pug">
  v-dialog(v-model='dialog', max-width='400' persistent)
    v-card
      v-card-title.headline {{ title }}
      v-card-text
        p {{ body }}
      v-card-actions
        v-spacer
        v-btn( text, @click='cancel')
          | 取消
        v-btn(color='primary', text, @click='confirm')
          | 确定
</template>
<script>
export default {
  name: 'lui-confirm',
  props: [],
  methods: {
    reset() {
      this.title = ''
      this.body = ''
      this.dialog = false
    },
    cancel() {
      this.reset()
      this.reject()
    },
    confirm() {
      this.reset()
      this.resolve()
    },
    show({ title, body }) {
      this.title = title
      this.body = body
      this.dialog = true
      return new Promise((resolve, reject) => {
        this.resolve = resolve
        this.reject = reject
      })
    }
  },
  computed: {},
  data() {
    return {
      resolve: () => {},
      reject: () => {},
      title: '',
      body: '',
      dialog: false
    }
  }
}
</script>